/*******************************************************************************
* Project: QSAR(Cute Software Architecture) 
*
* Copyright: Copyright(C) 2024 by YuetingBen, All Rights Reserved
*
* File name: CanCfg.h
*
* Brief: ;
*
* Author: Yueting.Ben
*
* Module: Can
*
*******************************************************************************/

#ifndef CANCFG_H
#define CANCFG_H

/** HEADER FILES **/
#include "CanType.h"
#include "CanRte.h" 


/** MACRO DEFINITION **/

/* @defgroup CAN_synchronisation_jump_width CAN Synchronization Jump Width */
#define CAN_SJW_1TQ                 (0x00000000U)              /*!< 1 time quantum */
#define CAN_SJW_2TQ                 ((uint32)CAN_BTR_SJW_0)  /*!< 2 time quantum */
#define CAN_SJW_3TQ                 ((uint32)CAN_BTR_SJW_1)  /*!< 3 time quantum */
#define CAN_SJW_4TQ                 ((uint32)CAN_BTR_SJW)    /*!< 4 time quantum */


/* @defgroup CAN_time_quantum_in_bit_segment_1 CAN Time Quantum in Bit Segment 1 */
#define CAN_BS1_1TQ                 (0x00000000U)                                                /*!< 1 time quantum  */
#define CAN_BS1_2TQ                 ((uint32)CAN_BTR_TS1_0)                                    /*!< 2 time quantum  */
#define CAN_BS1_3TQ                 ((uint32)CAN_BTR_TS1_1)                                    /*!< 3 time quantum  */
#define CAN_BS1_4TQ                 ((uint32)(CAN_BTR_TS1_1 | CAN_BTR_TS1_0))                  /*!< 4 time quantum  */
#define CAN_BS1_5TQ                 ((uint32)CAN_BTR_TS1_2)                                    /*!< 5 time quantum  */
#define CAN_BS1_6TQ                 ((uint32)(CAN_BTR_TS1_2 | CAN_BTR_TS1_0))                  /*!< 6 time quantum  */
#define CAN_BS1_7TQ                 ((uint32)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1))                  /*!< 7 time quantum  */
#define CAN_BS1_8TQ                 ((uint32)(CAN_BTR_TS1_2 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0))  /*!< 8 time quantum  */
#define CAN_BS1_9TQ                 ((uint32)CAN_BTR_TS1_3)                                    /*!< 9 time quantum  */
#define CAN_BS1_10TQ                ((uint32)(CAN_BTR_TS1_3 | CAN_BTR_TS1_0))                  /*!< 10 time quantum */
#define CAN_BS1_11TQ                ((uint32)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1))                  /*!< 11 time quantum */
#define CAN_BS1_12TQ                ((uint32)(CAN_BTR_TS1_3 | CAN_BTR_TS1_1 | CAN_BTR_TS1_0))  /*!< 12 time quantum */
#define CAN_BS1_13TQ                ((uint32)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2))                  /*!< 13 time quantum */
#define CAN_BS1_14TQ                ((uint32)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_0))  /*!< 14 time quantum */
#define CAN_BS1_15TQ                ((uint32)(CAN_BTR_TS1_3 | CAN_BTR_TS1_2 | CAN_BTR_TS1_1))  /*!< 15 time quantum */
#define CAN_BS1_16TQ                ((uint32)CAN_BTR_TS1) /*!< 16 time quantum */

#define CAN_BS2_1TQ                 (0x00000000U)                                /*!< 1 time quantum */
#define CAN_BS2_2TQ                 ((uint32)CAN_BTR_TS2_0)                    /*!< 2 time quantum */
#define CAN_BS2_3TQ                 ((uint32)CAN_BTR_TS2_1)                    /*!< 3 time quantum */
#define CAN_BS2_4TQ                 ((uint32)(CAN_BTR_TS2_1 | CAN_BTR_TS2_0))  /*!< 4 time quantum */
#define CAN_BS2_5TQ                 ((uint32)CAN_BTR_TS2_2)                    /*!< 5 time quantum */
#define CAN_BS2_6TQ                 ((uint32)(CAN_BTR_TS2_2 | CAN_BTR_TS2_0))  /*!< 6 time quantum */
#define CAN_BS2_7TQ                 ((uint32)(CAN_BTR_TS2_2 | CAN_BTR_TS2_1))  /*!< 7 time quantum */
#define CAN_BS2_8TQ                 ((uint32)CAN_BTR_TS2)                      /*!< 8 time quantum */


/** TYPEDEF DEFINITION **/
typedef uint8 CanControllerIdType;
#define CANCTL_ID_CAN0 ((CanControllerIdType)CanConf_HwHandle_Can_0) 
#define CANCTL_ID_CAN_MAX ((CanControllerIdType)CanConf_HwHandle_Can_Max) 

typedef uint32 CanControllerBaseAddressType;
typedef uint16 CanControllerBaudRateType;
typedef uint8 CanControllerPropSegType;
typedef uint32 CanControllerSeg1Type;
typedef uint32 CanControllerSeg2Type;
typedef uint32 CanControllerSyncJumpWidthType;

typedef struct
{
    CanControllerBaudRateType CanControllerBaudRate;
    CanControllerPropSegType CanControllerPropSeg;
    CanControllerSeg1Type CanControllerSeg1;
    CanControllerSeg2Type CanControllerSeg2;
    CanControllerSyncJumpWidthType CanControllerSyncJumpWidth;
}CanControllerBaudrateConfigType;


typedef struct
{
    CanControllerIdType CanControllerId;
    CanControllerBaseAddressType CanControllerBaseAddress;
    CanControllerBaudrateConfigType CanControllerBaudrateConfig;
}CanControllerType;

typedef struct
{
    uint32 CanHwFilterMask;
    uint32 CanHwFilterCode;
}CanHwFilterType;

typedef uint8 CanIdTypeType;
#define CANID_TYPE_STANDARD ((CanIdTypeType)(CAN_ID_STD))
#define CANID_TYPE_EXTENDED ((CanIdTypeType)(CAN_ID_EXT))
#define CANID_TYPE_MIXED ((CanIdTypeType)(2u))


typedef struct
{
    CanControllerType* CanControllerRef;
    CanHwFilterType CanHwFilter;
    CanIdTypeType CanIdType;
}CanHardwareObjectType;


typedef struct
{
    CanHardwareObjectType CanHardwareObject[CANCTL_ID_CAN_MAX];
}CanConfigSetType;

typedef struct
{
    uint8 CanIndex;
}CanGeneralType;


typedef struct
{
    CanGeneralType CanIndex;
    CanConfigSetType CanConfigSet;
}Can_ConfigType;

/** LOCAL DATA DEFINITION **/
extern const Can_ConfigType Can_Config;

#endif
